package AntFarm;
import java.util.HashSet;
import java.util.Set;

public class FoodInventory extends TileContent{

	private Set<Food> foods;
	private static int initialAmountOfFood = 1;


	public FoodInventory(){
		System.out.println(this.getClass().getName() + " created");
		
		this.foods = new HashSet<Food>();
		for(int i = 0; i < FoodInventory.initialAmountOfFood; i++)
		{
			this.foods.add(new Food());			
		}		
	}
	
	public void visit(TileContent tileContent) throws MovedToOtherTileException
	{
	System.out.println(tileContent.getClass().getName() + " visits " + this.getClass().getName() );
		try {
			tileContent.accept(this);	
		} catch (MovedToOtherTileException e) {
			throw e;
		}catch (CantMoveToThisTileEception e) {
			e.printStackTrace();
		}				
	}

	public Food removeFood(){
		if(this.foods.size() > 0){
		Food food =  (Food) this.foods.toArray()[0];
		this.foods.remove(food);
		return food;
		}
		return null;
	}

	
	public void accept(Ant ant){
		
		System.out.println(this.getClass().getName() + " accept " + ant.getClass().getName());		
		ant.pickUpFood(this.removeFood());		
	}

	public void accept(Food food){
		System.out.println(this.getClass().getName() + " accept" + food.getClass().getName());		
		foods.add(food);
		food.position.removeTileContent(food);		
	}



}